package juc.c_020;/*
   Talk is cheap. Show me the code.
 */

import java.util.concurrent.locks.ReentrantLock;

/**
 * @Description
 * @Date 2021/6/8
 * @Author liudl
 */
public class T05_ReentrantLock {
    private ReentrantLock lock = new ReentrantLock(false);
    private void m(){
        for (int i = 0; i < 50; i++) {
            lock.lock();
            try {
                System.out.println(Thread.currentThread().getName()+"获得锁");
            } finally {
                lock.unlock();
            }
        }
    }

    public static void main(String[] args) {
        T05_ReentrantLock t = new T05_ReentrantLock();
        new Thread(t::m).start();
        new Thread(t::m).start();
    }
}
